{% extends 'base.html' %}
{% block content %}
 (function () {
 		function randomPassword(size)
 		{
 		  var seed = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z',
 		  'a','b','c','d','e','f','g','h','i','j','k','m','n','p','Q','r','s','t','u','v','w','x','y','z',
 		  '2','3','4','5','6','7','8','9'
 		  );//数组
 		  seedlength = seed.length;//数组长度
 		  var createPassword = '';
 		  for (i=0;i<size;i++) {
 		    j = Math.floor(Math.random()*seedlength);
 		    createPassword += seed[j];
 		  }
 		  return createPassword;
 		}
 		// 添加按钮
 		addjson={
      	      "label": "新增教师",
      	      "type": "button",
      	      "actionType": "dialog",
      	      "level": "success",
      	      // "className": "m-b-sm",
      	      "dialog": {
      	        "title": "新增教师",
      	        "size":'lg',
      	        "body": {
      	          "type": "form",
      	          "data": {
      	                "password": randomPassword(8),
      	                'admin':randomPassword(6),
      	                // 'name':randomPassword(2),
      	                // 'cid':'513723199112024637',
  	              },
      	          "api": "post:/userdata",
      	          "reload": "window",
      	          "controls": [
      	            {
      	              "type": "text",
      	              "name": "admin",
      	              "label": "账号",
		            	required:1,
  	              		validations:{
		                	isAlphanumeric:1,
		                	minLength:5,
		                	maxLength:20,
		                },
      	            },
      	            {
      	              "type": "text",
      	              "name": "password",
      	              "value":"${spwd}",
      	              "label": "密码",
		            	required:1,
      	              validations:{
	          	        	minLength:6,
	          	        },
      	            },
      	            {
      	              "type": "text",
      	              "name": "name",
      	              "label": "姓名",
	            		required:1,

      	            },
      	            {
      	              "type": "text",
      	              "name": "cid",
      	              "label": "身份证",
	            		required:1,
    	              validations:{
	          	        	isLength:18,
	          	        },
      	            },
      	            {
      	              "type": "date",
      	              "name": "in_time",
      	              "label": "入职时间"
      	            },
      	            {
      	              "type": "date",
      	              "name": "oa_time",
      	              "label": "合同到期时间"
      	            },
      	            {
      	              "type": "date",
      	              "name": "out_time",
      	              "label": "离职时间"
      	            },
      	            {
      	                    "type": "rich-text",
      	                    "name": "info",
      	                    "label": "简介",
      	                    // "vendor": "froala",
      	                    'reciever':'post:/userdata/img',
      	                    "options": {
      	                              "menubar": false,
      	                              "height": 200,
      	                              "plugins": [
      	                                "advlist autolink lists link image charmap print preview anchor",
      	                                "searchreplace visualblocks code fullscreen",
      	                                "insertdatetime media table paste code help wordcount"
      	                              ],
      	                              "toolbar ": "undo redo | bold italic backcolor  | alignleft aligncenter alignright alignjustify |"
      	                            },
	                  }
      	          ]
      	        }
      	      }
      	    }
      	// 顶部搜索
      	topsertch={
	      "title": "搜索",
	      "controls": [
	        {
	          "type": "text",
	          "name": "name",
	          "placeholder": "姓名"
	        },
	        {
	          "type": "text",
	          "name": "cid",
	          "placeholder": "身份证"
	        },
	        {
	          "type": "datetime-range",
	          "name": "in_time",
	          "placeholder": "入职时间范围搜索"
	        },
	        {
	          "type": "datetime-range",
	          "name": "oa_time",
	          "placeholder": "合同时间范围搜索"
	        },
	        
	      ]
	    }


        var amis = amisRequire("amis/embed");
        // 用 amis 的 sdk 渲染内容区
        amis.embed("#main", {
          type: "page",
          title: "用户列表",
          // subTitle: "展示一些常规的表单，包括验证、提示等等",
          body: [
          	{
          	  "type": "page",
          	  "body": {
          	    "type": "crud",
          	    syncLocation: false,
          	    "api": "/userdata",
          	    "quickSaveItemApi": "put:/userdata/${id}",
          	    "saveImmediately":true,
          	  	"name":"userList",
          	    "filterTogglable": true,
          	  	"headerToolbar": [
          			addjson,
          	  		"filter-toggler",
          	  	],
      	  	    "footerToolbar": [
          	  	      "statistics",
          	  	      "switch-per-page",
          	  	      "pagination"
          	  	    ],
          	  	"filter":topsertch,
          	    "columns": [
          	      {
          	        "name": "id",
          	        "label": "ID"
          	      },
          	      {
          	        "name": "admin",
          	        "label": "账号"
          	      },
          	      {
          	        "name": "name",
          	        "searchable": true,
          	        "quickEdit": {
      	                  "type": "text",
      	                  validations:{
	          	        	maxLength:20,
	          	        },
  	                },
          	        "label": "姓名"
          	      },
          	      {
          	        "name": "cid",
          	        "label": "身份证",
          	        "searchable": true,
      	            "copyable": true,
          	        "quickEdit": {
      	                  "type": "text",
      	                  validations:{
      	                  	isNumeric:true,
	          	        	isLength:18,
	          	        },
  	                },
          	      },
          	      {
          	        "name": "in_time",
          	        "type":"date",
          	        "sortable": true,
          	        "quickEdit": {
  	                  "type": "date",
  	                },
          	        "label": "入职时间"
          	      },
          	      {
          	        "name": "oa_time",
          	        "type":"date",
          	        "sortable": true,
          	        "quickEdit": {
  	                  "type": "date",
  	                },
          	        "label": "合同到期时间"
          	      },
          	      {
          	        "name": "out_time",
          	        "type":"date",
          	        "sortable": true,
          	        "quickEdit": {
  	                  "type": "date",
  	                },
          	        "label": "离职时间"
          	      },
          	      {
          	        "name": "status",
          	        "type":"switch",
          	        "label": "是否开启",
          	        "quickEdit":{
  	                   "type": "switch",
          	        },
          	      },

          	      {
  	              "type": "operation",
  	              "label": "操作",
  	              "buttons": [
  	                {
  	                  "tooltip": "删除",
  	                  "type": "button",
  	                  "icon": "fa fa-times text-danger",
  	                  "actionType": "ajax",
  	                  // "level": "danger",
  	                  "confirmText": "确认要删除？",
  	                  "api": "delete:/userdata/${id}"
  	                },
  	                {
	                    "tooltip": "修改",
  	                  	"icon": "fa fa-pencil text-info",
	                    "type": "button",
	                    "actionType": "dialog",
	                    "dialog": {
	                      		"title": "修改教师",
      	        				"size":'lg',
      			      	        "body": {
      			      	          "type": "form",
      			      	          "data": {
      			  	              },
      			      	          "api": "put:/userdata/${id}",
      			      	          "reload": "window",
      			      	          "controls": [
      			      	            {
      			      	              "type": "text",
      			      	              "name": "admin",
      			      	              "label": "账号",
      					            	"disabled": true
      			      	            },
      			      	            {
      			      	              "type": "text",
      			      	              "name": "password",
      			      	              "value":"",
      			      	              "label": "密码",
      			      	              "remark":"不填则不修改",
      			      	              	validations:{
      				          	        	minLength:6,
      				          	        },
      			      	            },
      			      	            {
      			      	              "type": "text",
      			      	              "name": "name",
      			      	              "label": "姓名",
      				            		required:1,

      			      	            },
      			      	            {
      			      	              "type": "text",
      			      	              "name": "cid",
      			      	              "label": "身份证",
      				            		required:1,
      			    	              validations:{
      	                  					isNumeric:true,
      				          	        	isLength:18,
      				          	        },
      			      	            },
      			      	            {
      			      	              "type": "date",
      			      	              "name": "in_time",
      			      	              "label": "入职时间"
      			      	            },
      			      	            {
      			      	              "type": "date",
      			      	              "name": "oa_time",
      			      	              "label": "合同到期时间"
      			      	            },
      			      	            {
      			      	              "type": "date",
      			      	              "name": "out_time",
      			      	              "label": "离职时间"
      			      	            },
      			      	            {
      			      	                    "type": "rich-text",
      			      	                    "name": "info",
      			      	                    "label": "简介",
      			      	                    // "vendor": "froala",
      			      	                    'reciever':'post:/userdata/img',
      			      	                    "options": {
      			      	                              "menubar": false,
      			      	                              "height": 200,
      			      	                              "plugins": [
      			      	                                "advlist autolink lists link image charmap print preview anchor",
      			      	                                "searchreplace visualblocks code fullscreen",
      			      	                                "insertdatetime media table paste code help wordcount"
      			      	                              ],
      			      	                              "toolbar ": "undo redo | bold italic backcolor  | alignleft aligncenter alignright alignjustify |"
      			      	                            },
      				                  }
      			      	          ]
      			      	        }
	                    }
	                  },
	                 {
  	                  "tooltip": "重置密码",
  	                  "type": "button",
  	                  "icon": "fa fa-key text-warning",
  	                  "actionType": "ajax",
  	                  // "level": "danger",
  	                  "confirmText": "确认要重置密码为：123456",
  	                  "api": "put:/userdata/repwd/${id}"
  	                },
  	              ]
  	            }
          	    ]
          	  }
          	}





          ]
        });
      })();
{% endblock content %}